<script setup lang="ts">
import { FileUpload } from "@/components/common/FileUpload";
import { clearNoNum, clearSuffix } from "@/utils/inupt";
import { ref } from "vue";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    verticalProjectName: "",
    startDate: "",
    endDate: "",
    firstAccountDate: "",
    secondAccountDate: "",
    projectDate: [],
    level: "",
    projectMasterName: "",
    projectPartName: "",
    projectCertsFiles: "",
    contractFiles: "",
    projectType: 1,
    accountPrice: null,
    contractPrice: null,
    score: 0
  }),
  userList: null
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="110px"
    :inline="true"
    class="add-form"
  >
    <el-form-item label="纵向项目名称" prop="verticalProjectName">
      <el-input
        v-model="newFormInline.verticalProjectName"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="项目负责人" prop="projectMasterName">
      <el-input
        v-model="newFormInline.projectMasterName"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="项目参与人" prop="projectPartName">
      <el-input
        v-model="newFormInline.projectPartName"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="项目级别" prop="level">
      <el-select
        v-model="newFormInline.level"
        clearable
        placeholder="请选择"
        class="!w-[300px]"
      >
        <el-option key="国家级" label="国家级" value="国家级" />
        <el-option key="省部级" label="省部级" value="省部级" />
        <el-option key="市厅级" label="市厅级" value="市厅级" />
        <el-option key="校级" label="校级" value="校级" />
        <el-option key="其他" label="其他" value="其他" />
      </el-select>
    </el-form-item>
    <el-form-item label="合同金额" prop="contractPrice">
      <el-input
        v-model="newFormInline.contractPrice"
        placeholder="请输入"
        class="!w-[300px]"
        @input="$event => (newFormInline.contractPrice = clearNoNum($event))"
        @blur="
          newFormInline.contractPrice = clearSuffix(newFormInline.contractPrice)
        "
      >
        <template #suffix> 万元 </template>
      </el-input>
    </el-form-item>
    <el-form-item label="项目日期" prop="projectDate">
      <el-date-picker
        v-model="newFormInline.projectDate"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="YYYY-MM-DD"
      />
    </el-form-item>

    <el-form-item label="申报日期" prop="firstAccountDate">
      <el-date-picker
        v-model="newFormInline.firstAccountDate"
        type="date"
        placeholder="请选择"
        value-format="YYYY-MM-DD"
        class="!w-[300px]"
      />
    </el-form-item>

    <el-form-item label="获批日期" prop="secondAccountDate">
      <el-date-picker
        v-model="newFormInline.secondAccountDate"
        type="date"
        placeholder="请选择"
        value-format="YYYY-MM-DD"
        class="!w-[300px]"
      />
    </el-form-item>

    <el-form-item label="获取积分" prop="score">
      <el-input-number
        v-model="newFormInline.score"
        :min="0"
        placeholder="请输入"
        class="!w-[200px]"
      />
    </el-form-item>
    <el-form-item label="到账金额" prop="accountPrice">
      <el-input
        v-model="newFormInline.accountPrice"
        placeholder="请输入"
        class="!w-[300px]"
        @input="$event => (newFormInline.accountPrice = clearNoNum($event))"
        @blur="
          newFormInline.accountPrice = clearSuffix(newFormInline.accountPrice)
        "
      >
        <template #suffix> 万元 </template>
      </el-input>
    </el-form-item>
    <el-form-item label="合同附件" prop="contractFiles">
      <FileUpload v-model="newFormInline.contractFiles" :limit="15" />
    </el-form-item>
    <el-form-item label="立项证明文件" prop="projectCertsFiles">
      <FileUpload v-model="newFormInline.projectCertsFiles" :limit="15" />
    </el-form-item>
  </el-form>
</template>
